import 'package:financing_wallet/home/bean/basicInfoBean.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/color.dart';
import 'package:wallet_utils/event_bus_utils.dart';
import 'package:wallet_utils/ht_appbar.dart';
import 'package:wallet_utils/ht_common_widgets.dart';
import 'package:wallet_utils/msg_event_utils.dart';
import 'package:wallet_utils/safe_bottom_view.dart';
import 'package:wallet_utils/text_style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'logic.dart';

class OfflineProductPage extends StatelessWidget {
  final logic = Get.put(OfflineProductLogic());
  final state = Get.find<OfflineProductLogic>().state;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        EventBusUtils.getInstance().fire(MsgEventBusUtils(MsgEventBusUtils.popStatus,value: false));
        Get.until((route) => (route.settings.name == BaseRouterConfig.main));
        return Future.value(true);
      },
      child: Scaffold(
        appBar: htCommonAppbar(context, title: '匹配结果',leadingAction: (){
          EventBusUtils.getInstance().fire(MsgEventBusUtils(MsgEventBusUtils.popStatus,value: false));
          Get.until((route) => (route.settings.name == BaseRouterConfig.main));
        }),
        bottomNavigationBar: setBottomButton(
          context,
          '同意协议，激活额度',
          hasShadow: false,
          color: ColorManager.colorFFFFFF,
          onPressed: () {
            logic.jumpPage();
          },
        ),
        body: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/result_bg.png"),
              fit: BoxFit.fill,
            ),
          ),
          child: Column(
            children: [
              Container(
                margin: EdgeInsets.only(top: 20.w, left: 22.w),
                child: Row(
                  children: [
                    Image.asset('images/api_result_heade.png',width: 54.w,height: 57.w,),
                    SizedBox(
                      width: 5.w,
                    ),
                    Column(
                      children: [
                        Text(
                          '为您精选以下机构和产品',
                          style: TextStyleUtils.style000000(
                            fontSize: 16.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        Text(
                          '专业贷款咨询服务，在线秒接单',
                          style: TextStyleUtils.style000000(fontSize: 12.sp),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.all(15.w),
                margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 17.w, bottom: 10.w),
                decoration: const BoxDecoration(
                  color: Colors.white,
                  //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
                ),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Expanded(
                          child: Text(
                            '产品指定方案',
                            style: TextStyleUtils.style000000(
                              fontSize: 16.w,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Column(
                          children: [
                            Text(
                              '已选1个产品',
                              style: TextStyleUtils.style000000(fontSize: 16.sp),
                            ),
                            Text(
                              '(共可选1个产品)',
                              style: TextStyleUtils.style999999(fontSize: 11.sp),
                            ),
                          ],
                        ),

                      ],
                    ),
                    Container(
                      width: double.infinity,
                      height: 1.w,
                      color: ColorManager.colorEEEEEE,
                      margin: EdgeInsets.only(top: 5.w, bottom: 12.w),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        HtImage(
                          icon: true,
                          url: logic.productInfo?.imgUrl ?? '',
                          width: 24.w,
                          height: 24.w,
                          radius: 2,
                          placeholder: 'images/logo.png',
                          errImage: 'images/logo.png',
                        ),
                        SizedBox(
                          width: 5.w,
                        ),
                        Text(
                            logic.productInfo?.name ?? '',
                          style: TextStyleUtils.style000000(fontSize: 12.sp),
                        ),
                        SizedBox(
                          width: 5.w,
                        ),
                        Text(
                          logic.productInfo?.companyName ?? '',
                          style: TextStyleUtils.style999999(fontSize: 11.sp),
                        )
                      ],
                    ),
                  ],
                ),
              ),
              GetBuilder<OfflineProductLogic>(builder: (logic) {
                return Expanded(
                  child: Container(
                    width: double.infinity,
                    padding: EdgeInsets.only(top: 15.w, left: 15.w, right: 15.w),
                    margin: EdgeInsets.only(left: 16.w, right: 16.w),
                    decoration: const BoxDecoration(
                      color: Colors.white,
                      //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                      borderRadius: BorderRadius.only(topLeft: Radius.circular(8.0), topRight: Radius.circular(8.0)),
                    ),
                    child: ListView(
                      controller: state.scrollController,
                      shrinkWrap: true,
                      children: [
                        RichText(
                          text: TextSpan(
                            children: [
                              TextSpan(
                                text: "特别提醒:  ",
                                style: TextStyleUtils.colorFF7A1A(fontSize: 11.sp),
                              ),
                              TextSpan(
                                text: "${logic.productInfo?.name}会根据您的综合资信状况，为您推荐以下贷款机构产品:",
                                style: TextStyleUtils.style000000(
                                  fontSize: 11.sp,
                                ),
                              ),
                              TextSpan(
                                text: logic.productInfo?.companyName ??'',
                                style: TextStyle(
                                  color: ColorManager.color437EFF,
                                  fontSize: 11.sp,
                                  decoration: TextDecoration.underline,
                                ),
                                // 设置点击事件
                                recognizer: TapGestureRecognizer()..onTap = () {},
                              ),
                              TextSpan(
                                text: ",具体请阅读并同意相关协议",
                                style: TextStyleUtils.style000000(
                                  fontSize: 11.sp,
                                ),
                              ),
                              TextSpan(
                                text: "《个人信用查询授权书》",
                                style: TextStyle(
                                  color: ColorManager.color437EFF,
                                  fontSize: 11.sp,
                                ),
                                // 设置点击事件
                                recognizer: TapGestureRecognizer()..onTap = () {},
                              ),
                            ],
                          ),
                        ),
                        SizedBox(height: 10.w,),
                        HtmlWidget(
                          logic.productInfo?.content ?? '',
                          textStyle: TextStyleUtils.style000000(fontSize: 10.sp),
                        ),
                      ],
                    ),
                  ),
                );
              }),
            ],
          ),
        ),
      ),
    );
  }
}
